//
// Created by LiuYou on 2021/12/4.
//

#include <iostream>
#include <vector>
#include <iterator>


int main(int argc, char** argv) {
    {
        int arr[10];
        // 这里是两个指针相减。两个 int* 类型的指针相减, 结果即为数组的大小。
        unsigned long size = std::end( arr ) - std::begin( arr );

        std::cout << "size = " << size << std::endl;

        std::cout << "std::end( arr ) = " << std::end( arr ) << std::endl;
        std::cout << "std::begin(arr) = " << std::begin( arr ) << std::endl;

        fprintf( stdout, "std::end( arr ) = %p\n", std::end( arr ));
        fprintf( stdout, "std::begin( arr ) = %p\n", std::begin( arr ));

        for (const auto& item: arr) {
            std::cout << &item << " ";
        }
        std::cout << std::endl;
    }

    std::cout << "====================================================================" << std::endl;

    {
        std::vector<int> arr;

        std::cout << "arr.size() = " << arr.size() << std::endl;
        std::cout << "arr.capacity() = " << arr.capacity() << std::endl;
    }

    std::cout << "====================================================================" << std::endl;

    {
        std::vector<int> arr;
        arr.reserve( 10 );

        std::cout << "arr.size() = " << arr.size() << std::endl;
        std::cout << "arr.capacity() = " << arr.capacity() << std::endl;

        for (int i = 0; i < 10; ++i) {
            arr.emplace_back( 2 );
        }

        std::copy( arr.begin(), arr.end(), std::ostream_iterator<int>( std::cout, "\t" ));
        std::cout << std::endl;

        std::cout << "arr.size() = " << arr.size() << std::endl;
        std::cout << "arr.capacity() = " << arr.capacity() << std::endl;

    }

    std::cout << "====================================================================" << std::endl;

    {
        std::vector<int> arr( 10 );

        std::cout << "arr.size() = " << arr.size() << std::endl;
        std::cout << "arr.capacity() = " << arr.capacity() << std::endl;

        for (auto& item: arr) {
            item = 1;
        }

        std::copy( arr.begin(), arr.end(), std::ostream_iterator<int>( std::cout, "\t" ));
        std::cout << std::endl;

        std::cout << "arr.size() = " << arr.size() << std::endl;
        std::cout << "arr.capacity() = " << arr.capacity() << std::endl;

    }

    std::cout << "====================================================================" << std::endl;


    return 0;
}
